package com.example.web.controller;

import com.alibaba.fastjson.JSON;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.example.web.pojo.Result;
import com.example.web.utils.AliOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class ImageController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    @PostMapping("/uploadImage")
    public Result uploadImage(MultipartFile file) {
        try {
            String url = aliOSSUtils.uploadImage(file);
            return Result.success(url);
        } catch (IOException e) {
            return Result.error("上传失败");
        }
    }
}